home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / installed_progs / gfx / lise2.1 / lise / src / tekdaemon.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-11  |  34.9 KB  |  1,457 lines

  1. /* *********************************************************************
  2.   This programm reads and executes tektronix graphics
  3.   from the named pipe tek.pipe
  4.   the graphic cursor is send to /tmp/gcursor
  5.  *********************************************************************** */
  6.  
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9.  
  10. #include <stdio.h>
  11. #include <auxcfg.h>
  12. #include <spec.h>
  13. #include <signal.h>
  14.  
  15. #define _TEKXMAX 4096
  16. #define _TEKYMAX 3120
  17.  
  18.  
  19. int   cx,cy,cb1,cb2,
  20.       esc,fdcmds,
  21.       fdstdin,fdstdout,
  22.       fdtekout,
  23.       ink=2,
  24.        opt=1,
  25.        prt_passes=2,
  26.        prt_lsbmsb=1,
  27.        x_prt_siz=1024,
  28.        y_prt_siz=1024,
  29.        aposx=0,
  30.        aposy=0,
  31.        fdprinter=0,
  32.        pribufptr=0,
  33.        pribufsiz=8190,
  34.       paper=0,
  35.       ptr=0,
  36.       tekptr=0,
  37.       bufsiz=200000,
  38.       tekbufsiz=8192,     
  39.       nohco=FALSE,
  40.       msizex=3,
  41.       msizey=3,
  42.       sizex=3,
  43.       sizey=3,
  44.       sizex_1, sizey_1,
  45.       sizex_2, sizey_2,
  46.       thickx=1,
  47.       thicky=1,
  48.       txtangle=0,
  49.       sinphi=0,
  50.       cosphi=262144,
  51.       gramode=0,
  52.       flg_half=FALSE,
  53.       hcothick=FALSE,
  54.       bufferonfile=FALSE;
  55.  
  56. int            fdbuffer, fdptr;
  57. unsigned char  lastchar;
  58.  
  59. unsigned char  *tekname,
  60.                *tekoname,
  61.                 prt_init[80]="\x1B@",
  62.                 prt_gra[80]="\x1BZ",
  63.                 prt_halflf[80]="\x1B\x33\x02\n",
  64.                 prt_lf[80]="\x1B\x33\x14\n",
  65.                 prt_fin[80]="\x1B@\x0C",
  66.                 *primaryfont,
  67.                 *secondaryfont,
  68.                 *defaultprinter,
  69.                 *systemcommand,
  70.                 *bufferfile,
  71.               *buf,
  72.               *printerbuf,
  73.               *tekbuf,
  74.               *font_1,
  75.               *fontdesc_1,
  76.               *font_2,
  77.               *fontdesc_2,
  78.               *fontfile, *fontdesc;
  79.  
  80. int            *prop_1,
  81.                fontwidth_1, fontheight_1,
  82.                firstchar_1, offschar_1,
  83.                *prop_2,
  84.                fontwidth_2, fontheight_2,
  85.                firstchar_2, offschar_2,
  86.                *proptab,
  87.                fontwidth, fontheight,
  88.                firstchar, offschar;
  89.  
  90. int            prop_flag = 1;
  91. int            baseline = 0;
  92.  
  93. help()
  94. {
  95. printf("This is the server, which reads the named pipe for tektronix\n");
  96. printf("Vector grafic, and draws this grafic at the specified window\n");
  97. printf("call it like:\n(xterm -t -e tekdaemon [-p n])&\n");
  98. printf("optional parameters:\n");
  99. printf("    -p n         specifies a number for the pipe.\n");
  100. printf("    -buf n       change size of vector buffer(used for hardcopy)\n");
  101. printf("            The Vectorbuffer may also be specified in Aux_Config\n");
  102. printf("    -nohco       display only, no buffer for hardcopy\n");
  103. }
  104.  
  105.  
  106. teknewopen()
  107. {
  108. int   n,i,m,_tek4014;
  109. char  c,s[80],z[80];
  110.  
  111.  
  112.    strcpy(s,"gfx");
  113.    c=_tekpipe+48;
  114.    z[0]=c; z[1]=0;
  115.    strcat(s,z);
  116.    _tek4014=auxopen(s); /* _tekpipe is defined in spec.h */
  117.    strcpy(tekname,auxparams[0]);
  118.    if(_tek4014 > 0) { /* other programm active */
  119.       fprintf(stderr,"tekdaemon: graphic pipe >%s< allready exists\n",tekname);
  120.       fprintf(stderr,"you should delete it, before you try next time\n");
  121.       sleep(2);
  122.       if(!nohco) free(buf); free(tekbuf);
  123.       exit(0);
  124.    }
  125.    strcpy(primaryfont,auxparams[1]);
  126.    sizex_1 = atoi(auxparams[2]);
  127.    sizey_1 = atoi(auxparams[3]);
  128.    sizex = sizex_1; sizey = sizey_1;
  129.    msizex = sizex; msizey = sizey;
  130.    strcpy(secondaryfont,auxparams[4]);
  131.    sizex_2 = atoi(auxparams[5]);
  132.    sizey_2 = atoi(auxparams[6]);
  133.    strcpy(bufferfile,auxparams[7]);
  134.    if(bufferfile[0] > '9') {
  135.       bufferonfile = TRUE;
  136.    } else {
  137.       bufferonfile = FALSE;
  138.       bufsiz = atoi(bufferfile);
  139.    }
  140.    strcpy(defaultprinter,auxparams[8]);
  141.  
  142.    mknod(tekname,S_IFIFO | S_IROTH |S_IWOTH | S_IRUSR | S_IWUSR,0);
  143.    sprintf(s,"chmod a+rw \"%s\"",tekname); system(s);
  144.    _tek4014 = open(tekname,2);
  145.  
  146.    strcpy(tekoname,tekname); strcat(tekoname,"o");
  147.    mknod(tekoname,S_IFIFO | S_IROTH |S_IWOTH | S_IRUSR | S_IWUSR,0);
  148.    sprintf(s,"chmod a+rw \"%s\"",tekoname); system(s);
  149.    fdtekout = -1;
  150.  
  151.    return(_tek4014);
  152. }
  153.  
  154.  
  155. close_all()
  156. {
  157.   close(fdcmds);
  158.   if(fdtekout != -1) close(fdtekout);
  159.   unlink(tekname);
  160.   unlink(tekoname);
  161.   free(font_1); free(font_2); free(prop_1); free(prop_2);
  162.   free(tekname); free(primaryfont); free(secondaryfont);
  163.   free(defaultprinter); free(systemcommand); free(bufferfile);
  164.   if(bufferonfile) {
  165.       close(fdbuffer);
  166.       unlink(bufferfile);
  167.    } else {
  168.      if (!nohco) free(buf);
  169.   }
  170.   exit(0);
  171. }
  172.  
  173. main(argc,argv)
  174. int argc;
  175. char *argv[];
  176. {
  177. int  i,j,n,m,nohco,ioctlarg;
  178. char c,s[256],z[8192];
  179. char *env;
  180.  
  181.   _MAXSPCLEN = 64;
  182.   if(checkopt(argc,argv,"-dummy",z)) printf("(C) Rainer Kowallik\n");
  183.  
  184.   esc=FALSE;
  185.   fdstdin=fileno(stdin); /* may cause trouble when porting ! then you will */
  186.   fdstdout=fileno(stdout); /* have to find the filedescriptor by yourself */
  187.  
  188.   bufsiz=200000;
  189.  
  190.   tekbufsiz=8192;
  191.   nohco=FALSE;
  192.  
  193.    tekname = (unsigned char *) malloc(80);
  194.    tekoname = (unsigned char *) malloc(80);
  195.    primaryfont = (unsigned char *) malloc(80);
  196.    secondaryfont = (unsigned char *) malloc(80);
  197.    defaultprinter = (unsigned char *) malloc(80);
  198.    systemcommand = (unsigned char *) malloc(80);
  199.    bufferfile = (unsigned char *) malloc(80);
  200.  
  201.   fdcmds=teknewopen();
  202.    if(checkopt(argc,argv,"-buf",z)) {
  203.       strcpy(bufferfile,z);
  204.       if(bufferfile[0] > '9') {
  205.          bufferonfile = TRUE;
  206.       } else {
  207.          bufferonfile = FALSE;
  208.          bufsiz = atoi(bufferfile);
  209.       }
  210.    }
  211.  
  212.    if(checkopt(argc,argv,"-nohco",z)) nohco=TRUE;
  213.  
  214.    if(bufferonfile) {
  215.       fdbuffer = creat(bufferfile,0666);
  216.       close(fdbuffer);
  217.       fdbuffer = open(bufferfile,2,0666);
  218.    } else {
  219.       if(bufsiz < 1024) {
  220.          nohco = TRUE;
  221.       } else {
  222.          if(!nohco) buf = (unsigned char *)malloc(bufsiz+10);
  223.       }
  224.    }
  225.  
  226.  
  227.    font_1 = (unsigned char *) malloc(16384);
  228.    font_2 = (unsigned char *) malloc(16384);
  229.    prop_1 = (int *) calloc(256,sizeof(int));
  230.    prop_2 = (int *) calloc(256,sizeof(int));
  231.  
  232.    fontfile = font_2; proptab = prop_2;
  233.    readfont(secondaryfont);
  234.    fontdesc_2 = fontdesc;
  235.    fontheight_2 = fontheight;
  236.    fontwidth_2 = fontwidth;
  237.    firstchar_2 = firstchar;
  238.    offschar_2 = offschar;
  239.  
  240.    fontfile = font_1; proptab = prop_1;
  241.    readfont(primaryfont);
  242.    fontdesc_1 = fontdesc;
  243.    fontheight_1 = fontheight;
  244.    fontwidth_1 = fontwidth;
  245.    firstchar_1 = firstchar;
  246.    offschar_1 = offschar;
  247.  
  248.   ptr=0; tekptr=0;
  249.  
  250.   tekbuf=(unsigned char *)calloc(tekbufsiz,sizeof(char));
  251.  
  252.   signal(SIGKILL,close_all);
  253.  
  254.   while(1==1) {
  255.     n=read(fdcmds,z,8191);
  256.     if(n>0) {
  257.        m=writebuf(z,n); /* writebuf returns some flags */
  258.        if(m==-1) break;         /* quit flag */
  259.     } else {
  260.        close(fdcmds);
  261.        fdcmds=open(tekname,2);
  262.     }
  263.   }
  264.   close_all();
  265. }
  266.  
  267. /*
  268. The routine writebuf writes all tektronix vectors to the specified buffer,
  269. and searches for some specific actions. Every Clear Screen resets the buffer.
  270. if the buffer is full, no additional vectors are accepted.
  271. Values returned:
  272.    0   normal return
  273.    -1  program abort
  274. */
  275.  
  276. writebuf(s,n)
  277. char s[];
  278. int n;
  279. {
  280. int i,j,p,erg;
  281. char c,z[80],param[256];
  282.  
  283.    erg=0;                                /* assume normal return */
  284.  
  285.    for(i=0;i<n;i++) {
  286.       c=s[i];
  287.       if(esc) {                          /* trap escape sequences */
  288.          switch(c) {
  289.          case 0x1a :                     /* graphic cursor */
  290.             gfxbufin(c); tekflush();
  291.             z[0]=0; while(strlen(z)<5) fgets(z,80,stdin);
  292.             j=strlen(z)-5;
  293.             p=0; while(c!=0) {
  294.                c = z[j++];
  295.                z[p++] = c;
  296.             }
  297.             fdtekout = -1; 
  298.             while(fdtekout < 0) fdtekout = open(tekoname,1);
  299.             p=write(fdtekout,z,5);
  300.             close(fdtekout);
  301.             c=0;
  302.             break;
  303.          case 0x1c :                     /* request text length */
  304.             p=0;
  305.             c=1;
  306.             i=i+1;
  307.             while(c!=0) {
  308.                c=s[i++];
  309.                param[p++]=c;
  310.             }
  311.             i=i-1;
  312.             p = textlen(param);
  313.             sprintf(z,"%10d\n",p);
  314.             fdtekout = -1; 
  315.             while(fdtekout < 0) fdtekout = open(tekoname,1);
  316.             p=write(fdtekout,z,10);
  317.             close(fdtekout);
  318.             c=0;
  319.             break;
  320.          case 0x1e :                     /* request text height */
  321.             p = textheight();
  322.             sprintf(z,"%10d\n",p);
  323.             fdtekout = -1; 
  324.             while(fdtekout < 0) fdtekout = open(tekoname,1);
  325.             p=write(fdtekout,z,10);
  326.             close(fdtekout);
  327.             c=0;
  328.             break;
  329.          case 0x0c :                     /* clear screen => reset pointer */
  330.             ptr=0;
  331.  
  332.             sizex = sizex_1;
  333.             sizey = sizey_1;
  334.             fontfile = font_1;
  335.             proptab = prop_1;
  336.             fontdesc = fontdesc_1;
  337.             fontheight = fontheight_1;
  338.             fontwidth = fontwidth_1;
  339.             firstchar = firstchar_1;
  340.             offschar = offschar_1;
  341.             prop_flag = 1;
  342.  
  343.             if(bufferonfile) {
  344.                close(fdbuffer);
  345.                fdbuffer = creat(bufferfile,0666);
  346.                close(fdbuffer);
  347.                fdbuffer = open(bufferfile,2,0666);
  348.             }
  349.  
  350.             break;
  351.          case 0x40 :                     /* <esc>@ is now defined as quit */
  352.             erg = -1;
  353.             break;
  354.          case 0x1b :                     /* <esc><esc>: special action */
  355.             p=0;
  356.             c=1;
  357.             i=i+1;
  358.             while(c!=0) {
  359.                c=s[i++];
  360.                param[p++]=c;
  361.             }
  362.             i=i-1;
  363.             do_special(param); 
  364.             esc = FALSE;
  365.             break;
  366.          }
  367.          esc=FALSE;                      /* clear esc flag */
  368.       } 
  369.       esc=FALSE;
  370.       if(c==0x1b)  esc=TRUE;             /* set escape flag */
  371.       if(c==0x1f) {                      /* trap text sequence */
  372.          c=32; p=0; 
  373.          i=i+1;
  374.          if(s[i]==0x1b) {                /* handle textsize changes */
  375.             c=s[i+1];
  376.             switch(c) {
  377.             case ';':                    /* smallest text size */
  378.                sizex = msizex / 2;
  379.                sizey = msizey / 2;
  380.                break;
  381.             case ':':                    /* small text size */
  382.                sizex = (msizex * 2) / 3;
  383.                sizey = (msizey * 2) / 3;
  384.                break;
  385.             case '9':
  386.                sizex = msizex;            /* normal text size */
  387.                sizey = msizey;
  388.                break;
  389.             case '8':
  390.                sizex = 2 * msizex;        /* big text size */
  391.                sizey = 2 * msizey;
  392.                break;
  393.             }
  394.             i=i+2;
  395.          }
  396.          while(c>31) {
  397.             c=s[i++];
  398.             param[p++]=c;
  399.             if(i>n) break;
  400.          }
  401.          i=i-2;
  402.          c=0;
  403.          param[p-1]=0;                   /* set string end identifier */
  404.          plotstr(param);
  405.          continue;
  406.       }
  407.       if(c==0x1d) {               /* posita, store new position */
  408.          p=i+1;
  409.          gettekxy(s,&p,&cx,&cy);
  410.       }
  411.       gfxbufin(c); 
  412.    }
  413.    tekflush();
  414.    return(erg);
  415. }
  416.  
  417.  
  418. /* ---------------------------------------------------------------
  419.    Special actions: set text parameters and make hardcopy
  420.    --------------------------------------------------------------- */
  421. do_special(param)
  422. char param[];
  423. {
  424. int i,n,m,sx,sy,tx,ty,w;
  425. char c,s[80];
  426.  
  427.    sscanf(param,"%d",&n);
  428.  
  429.    hcothick = FALSE;
  430.    if(n > 127) {
  431.       hcothick = TRUE;
  432.       n = n && 127;
  433.    }
  434.  
  435.    strcpy(s,"");
  436.    switch(n) {
  437.    case 0 :                                     /* textparam */
  438.       sscanf(param,"%d %d %d %d %d %d %s",&i,&sx,&sy,&tx,&ty,&w,s);
  439.       if(sx>0) {sizex=sx; msizex=sx;}
  440.       if(sy>0) {sizey=sy; msizey=sy;}
  441.       if(tx>0) thickx=tx;
  442.       if(ty>0) thicky=ty;
  443.       if(s[0]!=0) readfont(s);
  444.       txtangle=w;
  445.       rotmat(w);
  446.       break;
  447.    case 1 :                                     /* hco */
  448.       sscanf(param,"%d %s",&i,s); 
  449.       hco(s);
  450.       break;
  451.    case 2 :
  452.       sscanf(param,"%d %s",&i,s);               /* print HP-GL */
  453.       save_hpgl(s,0,0);
  454.       break;
  455.    case 3 :
  456.       sscanf(param,"%d %s",&i,s);               /* print PostScript */
  457.       save_ps(s,0,0);
  458.       break;
  459.    case 5 :
  460.       sscanf(param,"%d %s",&i,s);               /* print Aegis Draw */
  461.       save_adraw(s,0,0);
  462.       break;
  463.    case 6 :
  464.       sscanf(param,"%d %s",&i,s);               /* print DXF */
  465.       save_dxf(s,0,0);
  466.       break;
  467.    }
  468. }
  469.  
  470.  
  471. cvtxy(xx,yy)
  472. int xx,yy;
  473. {
  474. int i,xh,xl,yh,yl;
  475. int x4, y4;
  476. char ch,cl;
  477.  
  478.    x4 = xx >> 2; y4 = yy >> 2;
  479.    yh = y4 >> 5; yl = y4 & 31;
  480.    xh = x4 >> 5; xl = x4 & 31;
  481.    i = (xx & 3) + 4 * (yy & 3); 
  482.    gfxbufin(yh | 32);
  483.    gfxbufin(i | 96);
  484.    gfxbufin(yl | 96);
  485.    gfxbufin(xh | 32);
  486.    gfxbufin(xl | 64);
  487. }
  488.  
  489.  
  490. gettekxy(s,p,x,y)
  491. char *s;
  492. int *p,*x,*y;
  493. {
  494. int xx,yy,i,l,h,ptr,k,z1,z2;
  495. char c;
  496.  
  497.    z1 = -1; z2 = -1;
  498.    xx = -1 ; yy = -1;
  499.    ptr = *p;
  500.    for(k=1;k<10;k++) {
  501.       if(s != NULL) {
  502.          c = s[ptr++];
  503.       } else {
  504.          c=getbuf(ptr++);
  505.       }
  506.       i=(c & 0xe0);
  507.       switch(i) {
  508.       case 32:
  509.          h = (c & 31);
  510.          break;
  511.       case 64:
  512.          l = (c & 31);
  513.          xx = (h*32 + l) << 2;
  514.          if(z2 != -1) xx = xx | z2;
  515.          break;
  516.       case 96:
  517.          l = (c & 31);
  518.          if(z1 != -1) {
  519.             yy = h*32 + l;
  520.             yy = (yy << 2) | (z1 >> 2);
  521.             z2 = z1 & 3;
  522.          } else {
  523.             yy = (h*32 + l) << 2;
  524.             z1 = l & 15;
  525.          }
  526.          break;
  527.       }
  528.       if((xx != -1) && (yy != -1)) break;
  529.    }
  530.    *x = xx; *y = yy; *p = ptr;
  531.    return(0);
  532. }
  533.  
  534.  
  535. posita(x,y)
  536. int x,y;
  537. {
  538.    int  n,m;
  539.  
  540.    gfxbufin(0x1d);
  541.    cvtxy(x,y);
  542. }
  543.  
  544. vectoa(x,y)
  545. int x,y;
  546. {
  547.    int  n,m;
  548.  
  549.    cvtxy(x,y);
  550. }
  551.  
  552.  
  553.  
  554. gfxbufin(c)
  555. char c;
  556. {
  557.    if(bufferonfile) {
  558.       write(fdbuffer,&c,1); 
  559.       ptr++; fdptr++;
  560.    } else {
  561.       if((ptr<bufsiz) & (!nohco)) buf[ptr++]=c;
  562.    }
  563.  
  564.    if(tekptr>=tekbufsiz) tekflush();
  565.    tekbuf[tekptr++]=c;
  566. }
  567.  
  568. tekflush()
  569. {
  570. write(fdstdout,tekbuf,tekptr);
  571. tekptr=0;
  572. }
  573.  
  574. getbuf(p)
  575. int p;
  576. {
  577.    if(bufferonfile) {
  578.       if(p == fdptr - 1) return(lastchar);
  579.       if(p == fdptr) {
  580.          read(fdbuffer,&lastchar,1);
  581.          fdptr++;
  582.          return(lastchar);
  583.       }
  584.       lseek(fdbuffer,p,0);
  585.       read(fdbuffer,&lastchar,1);
  586.       fdptr = p + 1;
  587.       return(lastchar);
  588.    } else {
  589.       return(buf[p]);
  590.    }
  591. }
  592.  
  593.  
  594. /* *********************************************************************
  595.  
  596.                   Vector font utilities
  597.  
  598.    ********************************************************************* */
  599.  
  600. /* ------------------------------------------------------------------
  601.       Read Vector font from file (as defined in Aux_Config)
  602.    ------------------------------------------------------------------ */
  603. readfont(name)
  604. char *name;
  605. {
  606. int n,i,m,xx,max;
  607. int yy,base;
  608. unsigned char *ptr;
  609. int fd;
  610. char *env, s[128];
  611.  
  612.    fd = open(name,0);
  613.    if(fd < 0) {
  614.       env = (char *) getenv("LISEPRG");
  615.       strcpy(s,env);
  616.       strcat(s,"/");
  617.       strcat(s,name);
  618.       fd = open(s,0);
  619.    }
  620.    if(fd < 0) {
  621.       fprintf(stderr,"Could not read font >%s<\nChange Aux_Config !\n",name);
  622.       unlink(tekname);
  623.       exit(-1);
  624.    }
  625.    read(fd,fontfile,16384);
  626.    close(fd);
  627.    n = 0;
  628.    while(fontfile[n] != 0x1a) if(n++ > 32767) break;
  629.    i = fontfile[n+1] + 256 * fontfile[n + 2];
  630.    ptr = &fontfile[i];
  631.    if(ptr[0] != 0x2b) {
  632.       printf("no font file\n");
  633.       exit(0);
  634.    }
  635.    offschar = i + ptr[5] + 256 * ptr[6];
  636.    firstchar = ptr[4];
  637.    fontheight = ptr[8] + ptr[11];
  638.    fontdesc = &ptr[18];
  639.    base = 0;
  640.    m = 128 - firstchar;
  641.    for(n = 0; n < m; n++) {         /* check fontwidth, generate prop table */
  642.       i = offschar + fontdesc[2 * n] + 256 * fontdesc[2 * n + 1];
  643.       ptr = &fontfile[i];
  644.       i = 0; max = 0;
  645.       while((ptr[i] & 0x80) != 0) {
  646.          xx = ptr[i++]; yy = ptr[i++];
  647.          xx = xx & 0x7f; yy = yy & 0x7f;
  648.          if(xx > max) max = xx;
  649.          if((yy & 0x40) != 0) {
  650.             yy = (yy & 0x3f) - 0x3f;
  651.             if(yy < base) base = yy;
  652.          }
  653.       }
  654.       max = max + 2;
  655.       proptab[n + firstchar + 1] = max;
  656.    }
  657.    base = -1 * base; fontheight = 0;
  658.    for(n = 0; n < m; n++) {         /* move baseline */
  659.       i = offschar + fontdesc[2 * n] + 256 * fontdesc[2 * n + 1];
  660.       ptr = &fontfile[i];
  661.       i = 0; max = 0;
  662.       while((ptr[i] & 0x80) != 0) {
  663.          i++; yy = ptr[i];
  664.          xx = yy; yy = yy & 0x7f;
  665.          if((yy & 0x40) != 0) yy = (yy & 0x3f) - 0x3f;
  666.          yy = yy + base;
  667.          if(yy > fontheight) fontheight = yy;
  668.          yy = yy | (xx & 0x80);
  669.          ptr[i++] = yy;
  670.       }
  671.    }
  672.    fontheight = fontheight / 2;
  673.    proptab[' '] = proptab['i'];
  674.    fontwidth = proptab['W'];
  675. }
  676.  
  677. textlen(s)
  678. char *s;
  679. {
  680. int c,i,n;
  681.  
  682.    i = 0; n = 0;
  683.    while(s[i] != 0) {
  684.       c = s[i++];
  685.       if(c == 92) {     /* meta character BACKSLASH ! */
  686.          i++;           /* ignore next character */
  687.          continue;
  688.       }
  689.       if(prop_flag == 1) {
  690.          n = n + sizex * proptab[c];
  691.       } else {
  692.          n = n + sizex * fontwidth;
  693.       }
  694.    }
  695.    n = n / 20; /* ????????????????????! */
  696.    return(n);
  697. }
  698.  
  699. textheight()
  700. {
  701. int h;
  702.  
  703.    h = sizey * fontheight / 10;
  704.    return(h);
  705. }
  706.  
  707. /* ------------------------------------------------------------------
  708.       Rotation
  709.    ------------------------------------------------------------------ */
  710. rotate(xx,yy)
  711. int *xx,*yy;
  712. {
  713. int rx,ry,x,y;
  714.  
  715.    x = *xx ; y = *yy;
  716.    rx = ((x * cosphi) >> 19) - (( y * sinphi) >> 19);
  717.    ry = (( y * cosphi) >> 19) + ((x * sinphi) >> 19);
  718.    *xx = rx ; *yy = ry;
  719. }
  720.  
  721. /* ------------------------------------------------------------------
  722.       plot one single character
  723.    ------------------------------------------------------------------ */
  724.  
  725. plotchar(c)
  726. int c;
  727. {
  728. int xx,yy;
  729. int ix,iy;
  730. int i,n;
  731. unsigned char *ptr;
  732.  
  733.    ix = cx; iy = cy;
  734.  
  735.    posita(ix,iy);
  736.  
  737.    n = c - firstchar - 1;
  738.    i = offschar + fontdesc[2 * n] + 256 * fontdesc[2 * n + 1];
  739.    ptr = &fontfile[i];
  740.    i = 0;
  741.    while((ptr[i] & 0x80) != 0) {
  742.       xx = ptr[i++]; yy = ptr[i++];
  743.       n = 0;
  744.       if((yy & 0x80) != 0) n = 1;
  745.       xx = xx & 0x7f; yy = yy & 0x7f;
  746.       xx = xx * sizex;
  747.       yy = yy * sizey;
  748.       rotate(&xx,&yy);
  749.       if(n == 1) {
  750.          vectoa(ix + xx, iy + yy);
  751.       } else {
  752.          posita(ix + xx, iy + yy);
  753.       }
  754.    }
  755.    xx = sizex * fontwidth; yy = 0;
  756.    if(prop_flag == 1) xx = sizex * proptab[c];
  757.    rotate(&xx ,&yy);
  758.    cx = ix + xx;
  759.    cy = iy + yy;
  760.    return(0);
  761. }
  762.  
  763. /* ------------------------------------------------------------------
  764.       plot string
  765.    ------------------------------------------------------------------ */
  766. plotstr(s)
  767. char s[];
  768. {
  769. int i,mx,my,tx,ty;
  770. int msizex, msizey, mprop;
  771. unsigned char c;
  772.  
  773.    cy = cy - 4;
  774.    msizex = sizex;
  775.    msizey = sizey;
  776.    mprop = prop_flag;
  777.    mx = cx ; my = cy;
  778.    for(tx=0;tx<thickx;tx++) {
  779.       for(ty=0;ty<thicky;ty++) {
  780.          cx = mx + tx;
  781.          cy = my + ty;
  782.          i=0;
  783.          baseline = 0;
  784.          sizex = msizex;
  785.          sizey = msizey;
  786.          fontfile = font_1;
  787.          proptab = prop_1;
  788.          fontdesc = fontdesc_1;
  789.          fontheight = fontheight_1;
  790.          fontwidth = fontwidth_1;
  791.          firstchar = firstchar_1;
  792.          offschar = offschar_1;
  793.          prop_flag = mprop;
  794.  
  795.          while(1==1) {
  796.             c = s[i++];
  797.             if(c==0) break;
  798.             if(c==92) {   /* meta character BACKSLASH ! */
  799.                c = s[i++];
  800.                switch(c) {
  801.                   case 'u':   /* superscript */
  802.                      baseline = baseline +1;
  803.                      if(baseline > 0) {
  804.                         cy = cy + ((sizey * fontheight) >> 1);
  805.                         sizex = (sizex << 2) / 5;
  806.                         sizey = (sizey << 2) / 5;
  807.                         continue;
  808.                      }
  809.                      if(baseline == 0) {
  810.                         cy = my + ty;
  811.                         sizex = msizex;
  812.                         sizey = msizey;
  813.                         continue;
  814.                      }
  815.                      if(baseline < 0) {
  816.                         cy = cy + ((sizey * fontheight) >> 1);
  817.                         sizex = (5 * sizex) >> 2;
  818.                         sizey = (5 * sizey) >> 2;
  819.                         continue;
  820.                      }
  821.                   case 'd':   /* subscript */
  822.                      baseline = baseline -1;
  823.                      if(baseline < 0) {
  824.                         cy = cy - ((sizey * fontheight) >> 1);
  825.                         sizex = (sizex << 2) / 5;
  826.                         sizey = (sizey << 2) / 5;
  827.                         continue;
  828.                      }
  829.                      if(baseline == 0) {
  830.                         cy = my + ty;
  831.                         sizex = msizex;
  832.                         sizey = msizey;
  833.                         continue;
  834.                      }
  835.                      if(baseline > 0) {
  836.                         cy = cy - ((sizey * fontheight) >> 1);
  837.                         sizex = (5 * sizex) >> 2;
  838.                         sizey = (5 * sizey) >> 2;
  839.                         continue;
  840.                      }
  841.                   case '1':   /* primary font */
  842.                         fontfile = font_1;
  843.                         proptab = prop_1;
  844.                         fontdesc = fontdesc_1;
  845.                         fontheight = fontheight_1;
  846.                         fontwidth = fontwidth_1;
  847.                         firstchar = firstchar_1;
  848.                         offschar = offschar_1;
  849.                         continue;
  850.                   case '2':   /* secondary font */
  851.                         fontfile = font_2;
  852.                         proptab = prop_2;
  853.                         fontdesc = fontdesc_2;
  854.                         fontheight = fontheight_2;
  855.                         fontwidth = fontwidth_2;
  856.                         firstchar = firstchar_2;
  857.                         offschar = offschar_2;
  858.                         continue;
  859.                   case '0':   /* proportional off */
  860.                         prop_flag = 0;
  861.                         continue;
  862.                   case 'b':   /* backspace */
  863.                         cx = (cx - (sizex * fontwidth) >> 1);
  864.                         continue;
  865.                }
  866.             }
  867.             plotchar(c);
  868.          }
  869.       }
  870.    }
  871.    baseline = 0;
  872.    sizex = msizex;
  873.    sizey = msizey;
  874.    fontfile = font_1;
  875.    proptab = prop_1;
  876.    fontdesc = fontdesc_1;
  877.    fontheight = fontheight_1;
  878.    fontwidth = fontwidth_1;
  879.    firstchar = firstchar_1;
  880.    offschar = offschar_1;
  881.    prop_flag = mprop;
  882.    return(0);
  883. }
  884.  
  885.  
  886. /* ----------------------------------------------------
  887.        Calculate rotation matrix
  888.    ---------------------------------------------------- */
  889.  
  890. rotmat(n)
  891. int n;      /* Angle in degree */
  892. {
  893. int i,m;
  894. float phi,cphi,sphi;
  895.  
  896.    phi = ((float) n) * 3.1415926 / 180.0;
  897.    cphi = 262144 * cos( phi );
  898.    sphi = 262144 * sin( phi );
  899.    sinphi = (int) sphi;
  900.    cosphi = (int) cphi;
  901. }
  902.  
  903. xtoi(s)
  904. char  s[];
  905. {  int i,m,l,e;
  906.    char c;
  907.  
  908.    l=strlen(s); e=0;
  909.    for( i = 0 ; i < l ; i++ ) {
  910.       c = s[i] ; c = toupper(c) ;
  911.       m = c - '0' ;
  912.       if( m > 9 ) m = m - 7 ;
  913.       e = 16 * e + m ;
  914.    } ;
  915.    return(e) ;
  916. }
  917.  
  918. /* ****************************************************************
  919.  
  920.                   HARDCOPY and related functions
  921.  
  922.    **************************************************************** */
  923.  
  924. hco(str)
  925. char str[];
  926. {
  927. unsigned char *bitplane;
  928. char z[80];
  929. int n;
  930.  
  931.    pribufsiz=8190;
  932.    pribufptr=0;
  933.    printerbuf=(unsigned char *)calloc(pribufsiz+2,sizeof(char));
  934.    if(buf==NULL) {
  935.       fprintf(stderr,"could not allocate printer buffer %d bytes\n",pribufsiz);
  936.       return(0);
  937.    }
  938.  
  939.  
  940.    strcpy(z,defaultprinter);
  941.    if(str[0]!=0) strcpy(z,str);
  942.    fdprinter=auxopen(z);
  943.    strcpy(systemcommand,auxparams[4]);
  944.  
  945.    n=5;
  946.    prt_passes=atoi(auxparams[n]); n=n+1;
  947.    prt_lsbmsb=atoi(auxparams[n]); n=n+1;
  948.    x_prt_siz=atoi(auxparams[n]); n=n+1;
  949.    y_prt_siz=atoi(auxparams[n]); n=n+1;
  950.  
  951.    if(prt_lsbmsb == 10) {
  952.       save_ps(auxparams[0],x_prt_siz,y_prt_siz);
  953.       system(systemcommand);
  954.       return(0);
  955.    }
  956.    if(prt_lsbmsb == 11) {
  957.       save_hpgl(auxparams[0],x_prt_siz,y_prt_siz);
  958.       system(systemcommand);
  959.       return(0);
  960.    }
  961.  
  962.    cvtbs(prt_init,auxparams[n]); n=n+1;
  963.    cvtbs(prt_gra,auxparams[n]); n=n+1;
  964.    cvtbs(prt_halflf,auxparams[n]); n=n+1;
  965.    cvtbs(prt_lf,auxparams[n]); n=n+1;
  966.    cvtbs(prt_fin,auxparams[n]);
  967.  
  968.    if(fdprinter <= 0) {
  969.       fdprinter = creat(auxparams[0],0666);
  970.       if(fdprinter <= 0) return(0);
  971.    }
  972.  
  973.    n = (x_prt_siz * y_prt_siz) / 8;     /* length of buffer needed */
  974.    n = n + 1024;                        /* to go shure */
  975.    bitplane=(unsigned char *)calloc(n,sizeof(char));
  976.    if(buf==NULL) {
  977.       fprintf(stderr,"could not allocate shadow memory %d bytes\n",n);
  978.       free(printerbuf);
  979.       close(fdprinter);
  980.       return(0);
  981.    }
  982.    redrawhco(bitplane);
  983.    printout(bitplane);
  984.    close(fdprinter);
  985.    free(bitplane); free(printerbuf); 
  986.    system(systemcommand);
  987.    return(0);
  988. }
  989.  
  990. strtoprt(s)
  991. unsigned char s[];
  992. {
  993. int n;
  994. unsigned char c;
  995.  
  996.    n=0;
  997.    while(1==1) {
  998.       c=s[n++];
  999.       if(c==0) break;
  1000.       pribufin(c);
  1001.    }
  1002. }
  1003.  
  1004. pribufin(c)
  1005. unsigned char c;
  1006. {
  1007. if(pribufptr>=pribufsiz) pribufflush();
  1008. printerbuf[pribufptr++]=c;
  1009. }
  1010.  
  1011. pribufflush()
  1012. {
  1013. write(fdprinter,printerbuf,pribufptr); 
  1014. pribufptr=0;
  1015. }
  1016.  
  1017. redrawhco(bitplane)
  1018. unsigned char *bitplane;
  1019. {
  1020. int x,y,i,n,m,p;
  1021. char c,s[80];
  1022.  
  1023.    p=0;
  1024.    while(getbuf(p)!=0x1d) p=p+1;          /* find posita first */
  1025.  
  1026.    while(p<ptr) {                      /* scan vector buffer */
  1027.  
  1028.       c=getbuf(p);
  1029.       if(c==0x1d) {
  1030.          p=p+1;
  1031.          gettekxy(NULL,&p,&x,&y);
  1032.          if((x>_TEKXMAX) | (y>_TEKYMAX)) {
  1033.             while(getbuf(p)!=0x1d) p=p+1;
  1034.             continue;
  1035.          }
  1036.          draw_to(bitplane,FALSE,x,y);
  1037.          continue;
  1038.       }
  1039.       if(c>31) {
  1040.          gettekxy(NULL,&p,&x,&y);
  1041.          if((x>_TEKXMAX) | (y>_TEKYMAX)) {
  1042.             while(getbuf(p)!=0x1d) p=p+1;
  1043.             continue;
  1044.          }
  1045.          draw_to(bitplane,TRUE,x,y);
  1046.          continue;
  1047.       }
  1048.       while(getbuf(p)!=0x1d) p=p+1;          /* find next posita */
  1049.    }
  1050. }
  1051.       
  1052. /* --------------------------------------------------------------- */
  1053. /*       Draw a line                                               */
  1054. /* --------------------------------------------------------------- */
  1055. draw_to(bitplane,pen_down,x,y)
  1056. unsigned char *bitplane;
  1057. int pen_down,x,y;
  1058. {
  1059.    int   xinc,yinc,
  1060.          xcount,ycount,
  1061.          fx,fy;
  1062.  
  1063.  
  1064.    x = (x_prt_siz * x) / _TEKXMAX ;
  1065.    y = (y_prt_siz * y) / _TEKYMAX ; y=y_prt_siz-y;
  1066.  
  1067.    if(pen_down == TRUE) {
  1068.       xinc=liabs(x-aposx);
  1069.       yinc=liabs(y-aposy);
  1070.       fx=lisgn(x-aposx);
  1071.       fy=lisgn(y-aposy);
  1072.       xcount=xinc;
  1073.       ycount=yinc;
  1074.       do {
  1075.          set_pixel(bitplane,aposx,aposy);
  1076.          if(hcothick) {
  1077.             set_pixel(bitplane,aposx+1,aposy);
  1078.             set_pixel(bitplane,aposx,aposy+1);
  1079.             set_pixel(bitplane,aposx+1,aposy+1);
  1080.          }
  1081.          if(xcount>ycount) {
  1082.             ycount=ycount+yinc ; aposx=aposx+fx;
  1083.          } else {
  1084.             xcount=xcount+xinc ; aposy=aposy+fy;
  1085.          }
  1086.       } while((liabs(x-aposx)>=1) || (liabs(y-aposy)>=1));
  1087.    }
  1088.    aposx=x; aposy=y;
  1089. }
  1090.  
  1091. liabs(x)
  1092. int x;
  1093. {
  1094.    if(x>=0) return(x);
  1095.    return(-x);
  1096. }
  1097.  
  1098. lisgn(x)
  1099. int  x;
  1100. {
  1101.    if(x>0) return(1L);
  1102.    if(x<0) return(-1L);
  1103.    return(0L);
  1104. }
  1105.  
  1106. /* --------------------------------------------------------------- */
  1107. /*       plot one pixel                                            */
  1108. /* --------------------------------------------------------------- */
  1109. set_pixel(bitplane,x,y)
  1110. unsigned char *bitplane;
  1111. int x,y;
  1112. {
  1113.    register int  byte,bit,n;
  1114.  
  1115.  
  1116.  
  1117.    byte=y*(x_prt_siz>>3)+(x>>3);
  1118.    bit= x & 7; n=128>>bit;
  1119.    bitplane[byte] |= n;
  1120. }
  1121.  
  1122. /* --------------------------------------------------------------- */
  1123. /*       get one pixel from shadow memory                          */
  1124. /* --------------------------------------------------------------- */
  1125. get_pixel(bitplane,x,y)
  1126. unsigned char *bitplane;
  1127. int x,y;
  1128. {
  1129.    register int   byte,bit;
  1130.    register unsigned char c;
  1131.  
  1132.    byte=y*(x_prt_siz>>3)+(x>>3);
  1133.    bit=7-(x & 7);
  1134.    c=((bitplane[byte])>>bit) & 1;
  1135.    return((int)c);
  1136. }
  1137.  
  1138. /* ----------------------------------------------------------- */
  1139. /*       get one byte ready to print from shadow memory        */
  1140. /* ----------------------------------------------------------- */
  1141. get_prtbyte(bitplane,x,y)
  1142. unsigned char *bitplane;
  1143. int x,y;
  1144. {
  1145.    int    i,m;
  1146.    long   n;
  1147.  
  1148.    m=0; n=0; x=x_prt_siz-x;
  1149.    for(i=1; i<=8; ++i) {
  1150.       n=n+prt_passes;
  1151.       m=2*m+get_pixel(bitplane,x-n,y);
  1152.    }
  1153.    return(m);
  1154. }
  1155.  
  1156. /* ----------------------------------------------------------- */
  1157. /*       make hardcopy of shadow memory                        */
  1158. /* ----------------------------------------------------------- */
  1159. printout(bitplane)
  1160. unsigned char *bitplane;
  1161. {
  1162.    long  x,y,i;
  1163.    unsigned char c;
  1164.  
  1165.  
  1166.    strtoprt(prt_init); pribufflush();
  1167.  
  1168.    if(prt_lsbmsb == 2) {              /* trap HP raster row graphics */
  1169.       hp_rasterrow(bitplane);
  1170.       return(0);
  1171.    }
  1172.  
  1173.    if(prt_lsbmsb == 3) {              /* trap HP DeskJet 500 */
  1174.       hp_deskjet(bitplane);
  1175.       return(0);
  1176.    }
  1177.  
  1178.    /* it follows the epson style printout routine */
  1179.  
  1180.    x=0;
  1181.    while(x<x_prt_siz) {
  1182.       y=0;
  1183.       for(i=1; i<=prt_passes; ++i) {
  1184.          prt_gra_out(y_prt_siz);
  1185.          while(y<y_prt_siz) {
  1186.             c=get_prtbyte(bitplane,x,y++);
  1187.             pribufin(c);
  1188.          }
  1189.          strtoprt(prt_halflf); 
  1190.          y=0; ++x;
  1191.       }
  1192.       strtoprt(prt_lf); pribufflush();
  1193.       x=x+7*prt_passes;
  1194.    }
  1195.  
  1196.    strtoprt(prt_fin); pribufflush();
  1197.    return(0);
  1198. }
  1199.  
  1200. /* -----------------------------
  1201.    HP mode raster row graphics 
  1202.    ----------------------------- */
  1203.  
  1204. hp_rasterrow(bitplane)
  1205. unsigned char *bitplane;
  1206. {
  1207.    int  n,x,m,i;
  1208.    unsigned char c;
  1209.  
  1210.  
  1211.    m = x_prt_siz / 8;
  1212.    n = (y_prt_siz -1) * m;
  1213.    x=0;
  1214.    while(x<n) {
  1215.       strtoprt(prt_gra);
  1216.       for(i=0; i<m; i++) {
  1217.          c=bitplane[x++];
  1218.          pribufin(c);
  1219.       }
  1220.       pribufflush();
  1221.    }
  1222.    strtoprt(prt_fin); pribufflush();
  1223.    return(0);
  1224. }
  1225.  
  1226. /* -----------------------------
  1227.       HP DeskJet mode  
  1228.    ----------------------------- */
  1229.  
  1230. hp_deskjet(bitplane)
  1231. unsigned char *bitplane;
  1232. {
  1233. int  x,y,i;
  1234. unsigned char c;
  1235.  
  1236.    x=0;
  1237.    while(x<x_prt_siz) {
  1238.       y = y_prt_siz - 1;
  1239.       strtoprt(prt_gra);
  1240.       while(y >= 0) {
  1241.          c = 0;
  1242.          for(i = 0; i < 8; i++) {
  1243.             c = (2 * c) + get_pixel(bitplane,x,y--);
  1244.          }
  1245.          pribufin(c);
  1246.       }
  1247.       pribufflush();
  1248.       x = x + 1;
  1249.    }
  1250.    strtoprt(prt_fin); pribufflush();
  1251.    return(0);
  1252. }
  1253.  
  1254. /* ------------------------------------------------------------ */
  1255. /* some printer dependend routines:                             */
  1256. /* ------------------------------------------------------------ */
  1257.  
  1258. prt_gra_out(x)
  1259. int  x;
  1260. {
  1261. unsigned char c1,c2;
  1262.  
  1263.    c1=x/256; c2=x-256*c1;
  1264.    strtoprt(prt_gra);
  1265.    if(prt_lsbmsb==1) {
  1266.       pribufin(c2);
  1267.       pribufin(c1);
  1268.    } else {
  1269.       pribufin(c1);
  1270.       pribufin(c2);
  1271.    }
  1272.    return(0);
  1273. }
  1274.  
  1275.  
  1276. /* convert string which includes the backslash */
  1277.  
  1278. cvtbs(s2,s1)
  1279. char s2[] , s1[];
  1280. {  int   l , i2 , i1 ;
  1281.    char  c , cc , s[8];
  1282.  
  1283.    l=strlen(s1); i2=0 ;
  1284.    for (i1 = 0; i1 <= l; i1++) {
  1285.       c=s1[i1];
  1286.       if(c == ' ') continue;
  1287.       if(c == '\\') {
  1288.          cc=s1[++i1];
  1289.          switch(cc) {
  1290.          case 'n':
  1291.             c='\n' ;  break ;
  1292.          case 'f':
  1293.             c='\f' ;  break ;
  1294.          case 't':
  1295.             c='\t' ;  break ;
  1296.          case 'b':
  1297.             c='\b' ;  break ;
  1298.          case 'x': /* hexadecimal conversion */
  1299.             s[0]=s1[++i1] ; s[1]=s1[++i1] ; s[2]=0 ;
  1300.             c=xtoi(s) ; break ;
  1301.          default:
  1302.             ; } ;
  1303.          } ;
  1304.       s2[i2++]=c ; }
  1305.    s2[i2]=0 ;
  1306.    return(i2-1);
  1307. }
  1308.  
  1309.  
  1310. /* ---------------------------------------------------------------
  1311.  
  1312.       Diverse Vektororientierte Ausgabe formate:
  1313.  
  1314.       HP-GL , DXF, PostScript
  1315.  
  1316.    --------------------------------------------------------------- */
  1317.  
  1318. vector_out(output,x_faktor,y_faktor,x_ofs,y_ofs,move_to,draw_to,bugfix)
  1319.  FILE *output;
  1320.  char move_to[], draw_to[];
  1321.  float x_faktor, y_faktor;
  1322.  float x_ofs, y_ofs;
  1323.  int bugfix;
  1324. {
  1325. int x,y,p;
  1326. float fx,fy,ofx,ofy;
  1327. char c;
  1328. int linecount;          /* This variable is introduced to work around a "bug" in most
  1329.                            PostScript interpreters, which have only restricted memory
  1330.                            capacities                                                 */
  1331.  
  1332.    p=0; linecount = 0;
  1333.    while(getbuf(p)!=0x1d) p = p + 1;   /* find posita first */
  1334.  
  1335.    while(p<ptr) {                      /* scan vector buffer */
  1336.       c=getbuf(p);
  1337.       if(c==0x1d) {
  1338.          p=p+1;
  1339.          gettekxy(NULL,&p,&x,&y);
  1340.          if((x < 0) | (y < 0) | (x>_TEKXMAX) | (y>_TEKYMAX)) {
  1341.             while(getbuf(p)!=0x1d) p=p+1;
  1342.             continue;
  1343.          }
  1344.          ofx = (x_faktor * x) + x_ofs;
  1345.          ofy = (y_faktor * y) + y_ofs;
  1346.          if(bugfix != 2) fprintf(output,move_to,ofx,ofy);
  1347.          linecount = 0;
  1348.          continue;
  1349.       }
  1350.       if(c>31) {
  1351.          gettekxy(NULL,&p,&x,&y);
  1352.          if((x < 0) | (y < 0) | (x>_TEKXMAX) | (y>_TEKYMAX)) {
  1353.             while(getbuf(p)!=0x1d) p=p+1;
  1354.             continue;
  1355.          }
  1356.          fx = (x_faktor * x) + x_ofs;
  1357.          fy = (y_faktor * y) + y_ofs;
  1358.          if(bugfix == 2) {   /* DXF special treatment */
  1359.             fprintf(output,move_to,ofx,ofy);
  1360.             ofx = fx; ofy = fy;
  1361.          }
  1362.          fprintf(output,draw_to,fx,fy);
  1363.          if((linecount++ > 20) && (bugfix == 1)) {   /* work around PostScript "bug" */
  1364.             linecount = 0;
  1365.             fprintf(output,move_to,fx,fy);
  1366.          }
  1367.          continue;
  1368.       }
  1369.       while(getbuf(p)!=0x1d) p = p + 1;   /* find next posita */
  1370.    }
  1371.    return(0);
  1372. }
  1373.  
  1374.  
  1375. save_hpgl(s,xsize,ysize)
  1376. char *s;
  1377. int xsize,ysize;
  1378. {
  1379. FILE *output;
  1380.  
  1381.    output = fopen(s,"w");
  1382.    fprintf(output,"IN;\nLT;\n1;\n");
  1383.    vector_out(output,(float)15,(float)15,(float)0,(float)0,
  1384.       "PU;PA %5.0f,%5.0f;\n",
  1385.       "PD;PA %5.0f,%5.0f;\n",0);
  1386.    fprintf(output,"PU;SP;IP;SC;PA 0,7650\n");
  1387.    fclose(output);
  1388.    return(0);
  1389. }
  1390.  
  1391. save_adraw(s,xsize,ysize)
  1392. char *s;
  1393. int xsize, ysize;
  1394. {
  1395. FILE *output;
  1396. float x_factor, y_factor;
  1397.  
  1398.    x_factor = 0.24;
  1399.    y_factor = 0.24;
  1400.  
  1401.    output = fopen(s,"w");
  1402.    fprintf(output,"81086 0.00000 0.00000 1000.0 1000.0 0 1.00000 \"lise.out\"\n-1\n");
  1403.    fprintf(output,"1 52 0.0 0.0 1000.0 1000.0 0 0 0 0 0\n");
  1404.    vector_out(output,x_factor,y_factor,0.0,0.0,
  1405.       "   0\n1 52 0.0 0.0 1000.0 1000.0 0 0 0 0 0\n   1 %4.3f %4.3f\n",
  1406.       "   1 %4.3f %4.3f\n",0);
  1407.    fprintf(output,"   0\n-1\n");
  1408.    fclose(output);
  1409.    return(0);
  1410. }
  1411.  
  1412. save_dxf(s,xsize,ysize)
  1413. char *s;
  1414. int xsize, ysize;
  1415. {
  1416. FILE *output;
  1417. float x_factor, y_factor;
  1418.  
  1419.    x_factor = 0.24;
  1420.    y_factor = 0.24;
  1421.  
  1422.    output = fopen(s,"w");
  1423.    fprintf(output,"0\nSECTION\n");
  1424.    fprintf(output,"2\nENTITIES\n");
  1425.  
  1426.    vector_out(output,x_factor,y_factor,0.0,0.0,
  1427.       "0\nLINE\n8\n0\n10\n %4.3f\n20\n %4.3f\n",
  1428.       "11\n %4.3f\n21\n %4.3f\n",2);
  1429.  
  1430.    fprintf(output,"0\nENDESEC\n");
  1431.    fprintf(output,"0\nEOF\n");
  1432.  
  1433.    fclose(output);
  1434.    return(0);
  1435. }
  1436.  
  1437. save_ps(str,xsize,ysize)
  1438. char *str;
  1439. int xsize, ysize;
  1440. {
  1441. FILE *output;
  1442. float x_factor, y_factor;
  1443.  
  1444.    x_factor = (float) xsize / 100.0; if(xsize == 0) x_factor = 0.125;
  1445.    y_factor = (float) ysize / 100.0; if(ysize == 0) y_factor = 0.125;
  1446.  
  1447.    output = fopen(str,"w");
  1448.    fprintf(output,"%c!PS-Adobe-1.0\n",'%');
  1449.    vector_out(output, x_factor, y_factor , 10.0, 30.0,
  1450.       "0.4 setlinewidth\nstroke\n%4.2f %4.2f moveto\n",
  1451.       "%4.1f99 %4.1f99 lineto\n",1);
  1452.    fprintf(output,"0.4 setlinewidth\nstroke\nshowpage\n");
  1453.    fclose(output);
  1454.    return(0);
  1455. }
  1456.  
  1457.